import subprocess
import time
import fcntl
import os
from time import sleep


# def non_block_read(output):
#     fd = output.fileno()
#     fl = fcntl.fcntl(fd, fcntl.F_GETFL)
#     fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
#     try:
#         return output.read()
#     except:
#         return ""


# proc = subprocess.Popen(
#     ['ping', "www.baidu.com"],
#     # proc = subprocess.Popen(['cat', "/etc/passwd"],
#     stdout=subprocess.PIPE)

# non_block_read(proc.stdin)
# while proc.poll() is None:
#     seconds_passed = time.time() - t_beginning
#     if seconds_passed > OUTTIME:
#         proc.terminate()
#         break
while True:
    print(proc.stdout.readline())
    sleep(1)
# while proc.poll() is None:
#     pass
#
# print(proc.poll())
# print(proc.stdout.read())
